package com.cuanbobox.adapter;

import android.os.Environment;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cuanbobox.activity.MainActivity;
import com.cuanbobox.activity.PreviewActivity;
import com.cuanbobox.base.App;
import com.cuanbobox.bean.EventBusBean;
import com.cuanbobox.bean.WdsBean;
import com.cuanbobox.bean.WdsDataList;
import com.cuanbobox.cbavcx.R;
import com.cuanbobox.utils.ActivityUtil;
import com.cuanbobox.utils.ImgUtil;
import com.cuanbobox.utils.LogUtil;

import org.greenrobot.eventbus.EventBus;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class WdsAdapter extends BaseQuickAdapter<WdsBean, BaseViewHolder> implements BaseQuickAdapter.OnItemClickListener {

    public WdsAdapter(List<WdsBean> list) {
        super(R.layout.adapter_wds_item, list);
        setOnItemClickListener(this);
    }

    @Override
    protected void convert(BaseViewHolder helper, WdsBean item) {
        ImageView ivImg=helper.getView(R.id.ivImg);
        if(item.getName().equals("返回桌面")){
            ivImg.setImageResource(R.drawable.wds);
        }else if(item.getName().equals("Weixin")){
            ivImg.setImageResource(R.drawable.wx);
        }else if(item.getName().equals("msedge")){
            ivImg.setImageResource(R.drawable.edge);
        }else if(item.getName().equals("chrome")){
            ivImg.setImageResource(R.drawable.gg);
        }else{
            try{
                ivImg.setImageBitmap(ImgUtil.getBitmapByBase64(item.getBase64Img()));
            }catch (Exception e){
                LogUtil.addError("-----------------base64图片展示失败-------------------");
                LogUtil.addError(e);
            }
        }

/*        if(item.getTitle().contains("-")){
            String[] str=item.getTitle().split("-");;
            helper.setText(R.id.tvName,""+str[0]);
        }else{
            helper.setText(R.id.tvName,""+item.getTitle());
        }*/
        helper.setText(R.id.tvName,""+item.getName());

    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        WdsBean bean=getItem(position);
        if(position==0){
            WdsDataList.add(">Desktop.");
        }else{
            WdsDataList.add(">OpenWindow:"+bean.getName()+".");
        }

    }

}